package com.example.tellwin.mine.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.tellwin.MainApplication;
import com.example.tellwin.R;
import com.example.tellwin.common.Common;
import com.example.tellwin.mine.bean.ExpenseRecordBean;
import com.example.tellwin.utils.CommonUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * @author : LinZePeng
 * @date : 2020/11/16
 * @Describe ：
 **/
public class ExpenseRecordAdapter extends RecyclerView.Adapter<ExpenseRecordAdapter.ExpenseRecordViewHolder> {

    List<ExpenseRecordBean> expenseRecordBeans = new ArrayList<>();
    Context context;

    public void setExpenseRecordBeans(List<ExpenseRecordBean> expenseRecordBeans) {
        this.expenseRecordBeans = expenseRecordBeans;
        notifyDataSetChanged();
    }

    @NonNull
    @Override
    public ExpenseRecordAdapter.ExpenseRecordViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        context = parent.getContext();
        return new ExpenseRecordViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_expense_record, parent, false));
    }

    @Override
    public void onBindViewHolder(@NonNull ExpenseRecordAdapter.ExpenseRecordViewHolder holder, int position) {
        ExpenseRecordBean expenseRecordBean = expenseRecordBeans.get(position);
        holder.recordTimeTv.setText(expenseRecordBean.getCreateTime());
        double money = 0;
        if (expenseRecordBean.getMoney() != null && CommonUtils.isNumeric(expenseRecordBean.getMoney())) {
            money = Double.valueOf(expenseRecordBean.getMoney());
        }
        if (MainApplication.Identity.equals(Common.NORMAL)) {
            if (expenseRecordBean.getAccountType() == 1) {
                holder.recordTypeTv.setText(R.string.recharge);
                holder.recordMoneyTv.setText("+￥" + money);
                holder.recordMoneyTv.setTextColor(context.getResources().getColor(R.color.color_d94850));
            } else if (expenseRecordBean.getAccountType() == 3) {
                holder.recordTypeTv.setText(R.string.expense);
                holder.recordMoneyTv.setText("-￥" + money);
                holder.recordMoneyTv.setTextColor(context.getResources().getColor(R.color.theme_color));
            } else if (expenseRecordBean.getAccountType() == 4) {
                holder.recordTypeTv.setText("积分获取");
                holder.recordMoneyTv.setText("+￥" + money);
                holder.recordMoneyTv.setTextColor(context.getResources().getColor(R.color.color_d94850));
            } else if (expenseRecordBean.getAccountType() == 5) {
                holder.recordTypeTv.setText("积分兑换");
                holder.recordMoneyTv.setText("+￥" + money);
                holder.recordMoneyTv.setTextColor(context.getResources().getColor(R.color.color_d94850));
            } else if (expenseRecordBean.getAccountType() == 6) {
                holder.recordTypeTv.setText("系统赠送");
                holder.recordMoneyTv.setText("+￥" + money);
                holder.recordMoneyTv.setTextColor(context.getResources().getColor(R.color.color_d94850));
            }
        } else if (MainApplication.Identity.equals(Common.ANSWER)) {
            if (expenseRecordBean.getAccountType() == 3) {
                holder.recordTypeTv.setText("收入");
                holder.recordMoneyTv.setText("+￥" + money);
                holder.recordMoneyTv.setTextColor(context.getResources().getColor(R.color.color_d94850));
            } else if (expenseRecordBean.getAccountType() == 2) {
                holder.recordTypeTv.setText("提现");
                holder.recordMoneyTv.setText("-￥" + money);
                holder.recordMoneyTv.setTextColor(context.getResources().getColor(R.color.theme_color));
            } else if (expenseRecordBean.getAccountType() == 6) {
                holder.recordTypeTv.setText("系统赠送");
                holder.recordMoneyTv.setText("+￥" + money);
                holder.recordMoneyTv.setTextColor(context.getResources().getColor(R.color.color_d94850));
            }

            /*else if (expenseRecordBean.getAccountType() == 4) {
                holder.recordTypeTv.setText("积分获取");
                holder.recordMoneyTv.setText("+￥" + money);
                holder.recordMoneyTv.setTextColor(context.getResources().getColor(R.color.color_d94850));
            }else if (expenseRecordBean.getAccountType() == 5) {
                holder.recordTypeTv.setText("积分兑换");
                holder.recordMoneyTv.setText("+￥" + money);
                holder.recordMoneyTv.setTextColor(context.getResources().getColor(R.color.color_d94850));
            }*/

           /* if (expenseRecordBean.getMoney() >= 0) {
                holder.recordTypeTv.setText(expenseRecordBean.getNumber());
            }else {
                holder.recordTypeTv.setText("银行卡提现");
                holder.recordStateTv.setText("审核通过");
            }*/
        }

    }

    @Override
    public int getItemCount() {
        return expenseRecordBeans.size();
    }


    class ExpenseRecordViewHolder extends RecyclerView.ViewHolder {

        TextView recordTypeTv;
        TextView recordTimeTv;
        TextView recordMoneyTv;
        TextView recordStateTv;

        public ExpenseRecordViewHolder(@NonNull View itemView) {
            super(itemView);
            recordTypeTv = (TextView) itemView.findViewById(R.id.record_type_tv);
            recordTimeTv = (TextView) itemView.findViewById(R.id.record_time_tv);
            recordMoneyTv = (TextView) itemView.findViewById(R.id.record_money_tv);
            recordStateTv = itemView.findViewById(R.id.record_state_tv);
        }
    }
}
